package demo.jdk.features.jdk7;

import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * @author Ranchoz  2018/9/9 15:21
 **/
public class PathUsage {
	public void usePath() {
		Path path1 = Paths.get("folder1", "sub1");
		System.out.println("[path1] -> " + path1);
		Path path2 = Paths.get("folder2", "sub2");  // folder1\sub1
		Path p3 = path1.resolve(path2); //    folder1\sub1\folder2\sub2
		System.out.println("[path1] -> " + path1);
		System.out.println("[path2] -> " + path2);
		System.out.println("[p3] -> " + p3);
		Path p4 = path1.resolveSibling(path2); // folder1\folder2\sub2
		System.out.println("[p4] -> " + p4);
		Path p5 = path1.relativize(path2); //     ..\..\folder2\sub2
		System.out.println("[p5] -> " + p5.toString());
		Path p6 = path1.subpath(0, 1); //     folder1
		System.out.println("[p6] -> " + p6);
		path1.startsWith(path2); //     false
		path1.endsWith(path2); //   false
		Path p7 = Paths.get("folder1/./../folder2/my.text").normalize(); //folder2\my.text
		System.out.println("[p7] -> " + p7);
	}

	/**
	 * @param args the command line arguments
	 */
	public static void main(String[] args) {
		PathUsage usage = new PathUsage();
		usage.usePath();
	}
}
